package com.aplink.generic.util;

import android.app.Activity;
import android.os.AsyncTask;

import com.google.android.gms.maps.model.LatLng;

import org.w3c.dom.Document;

import java.util.ArrayList;

public class GetRouteTask extends AsyncTask<String, String, ArrayList<LatLng>> {

    Activity act;
    Document document;
    LatLng fromPosition;
    LatLng toPosition;
    MapV2GetRouteDirection v2GetRouteDirection;

    public GetRouteTask( Activity _act, LatLng fromposition, LatLng toposition ) {
        this.act = _act;
        this.fromPosition = fromposition;
        this.toPosition = toposition;
        this.v2GetRouteDirection = new MapV2GetRouteDirection();

    }

    @Override
    protected ArrayList<LatLng> doInBackground( String... arg0 ) {
        // Get All Route values
        try {
            this.document = this.v2GetRouteDirection.getDocument( this.fromPosition,
                    this.toPosition, MapV2GetRouteDirection.MODE_DRIVING );
            if ( this.document != null ) {
                return this.v2GetRouteDirection
                        .getDirection( this.document );
            }
        } catch ( final Exception e ) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute( ArrayList<LatLng> result ) {
        // TODO Auto-generated method stub
        // use when you choose the new direction from the map
        /*
         * Dialog.dismiss(); if (exception == null) {
		 * act.handleGetDirectionsResult(result); } else { processException(); }
		 */

        super.onPostExecute( result );
    }

}
